<template>
  <div class="app-container">
    <el-table :data="list" style="width: 100%">
      <el-table-column prop="id" label=""> </el-table-column>
      <el-table-column prop="borrowAmount" label="借款额度"> </el-table-column>
      <el-table-column
        prop="integralStart"
        label="积分区间开始"
      ></el-table-column>
      <el-table-column
        prop="integralEnd"
        label="积分区间结束"
      ></el-table-column>
      <el-table-column prop="" label="操作">
        <template slot-scope="scope">
          <router-link :to="'/core/integral-grade/edit/' + scope.row.id">
            <!-- 修改，是一个超链接，页面会跳转-->

            <el-button type="primary" icon="el-icon-edit" circle></el-button>
          </router-link>
          <!-- 删除按钮-->
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="removeById(scope.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import integralGrade from '@/api/core/integral-grade'
export default {
  data() {
    return {
      list: [],
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      integralGrade.list().then((response) => {
        this.list = response.data.list
      })
    },
    removeById(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return integralGrade.removeById(id)
        })
        .then((response) => {
          this.$message({
            type: 'success',
            message: '删除成功!',
          })
          this.fetchData() //刷新当前的列表页
        })
        .catch((error) => {
          console.log('catch的error是：' + error)
          if (error === cancel) {
            this.$message({
              type: 'info',
              message: '已取消删除',
            })
          }
        })
    },
  },
}
</script>
